<?php
class VideoCreate {
	
	function getVideoCode ($url) {
		if (!is_string($url) || empty($url)) return false;
		$url = str_replace("&amp;", "&", $url);
		$arr = parse_url($url);
		$arr['host'] = str_replace('www.', '', $arr['host']);
		$url = "";
		
		switch ($arr['host']) {
			case 'youtube.com':
				$id = str_replace('v=', '', $arr['query']);
				$code = '<iframe width="100%" height="100%" src="http://www.youtube.com/embed/'.$id;
				$code .= '?showinfo=0" frameborder="0" allowfullscreen></iframe>';
				break;
			case 'youtu.be':
				$id = str_replace('/', '', $arr['path']);
				$code = '<iframe width="100%" height="100%" src="http://www.youtube.com/embed/'.$id;
				$code .= '?showinfo=0" frameborder="0" allowfullscreen></iframe>';
				break;
			case 'player.vimeo.com':
			case 'vimeo.com':
				$id = str_replace('/', '', $arr['path']);
				$code = '<iframe src="http://player.vimeo.com/video/'.$id;
				$code .= '" width="100%" height="100%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
				break;
			case 'video.rutube.ru':
			case 'rutube.ru':
				$id = str_replace('/', '', str_replace('/video/', '', $arr['path']));
				$xml = simplexml_load_file("http://rutube.ru/cgi-bin/xmlapi.cgi?rt_mode=movie&rt_movie_id=".$id."&utf=1");
				if ($xml) {
					$url = (string) $xml->embed_url;
					$code = '<iframe width="100%" height="100%" src="'.$url;
					$code .= '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen scrolling="no"></iframe>';
				}
				break;
			default:
				$code = "";
				break;
		}
		//print_r($code);
		//exit;
		return $code;
	}
}
?>